﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using LdExpress;
public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnLogin_Click(object sender, EventArgs e)
    {
        AdminUser adminUser = new AdminUser();
        int userID = adminUser.Login(Request.Form["txtUserName"].ToString(), Request.Form["txtPassword"].ToString(), GV.cn, GV.trans);
        if (userID > 0)
        {
            Session["logined_id"] = userID;
            AdminUser users = new AdminUser();
            users.ID = userID;
            users.Load(GV.cn, GV.trans);
            Session["UserProvince"] = users.IdProvince.ToString();
            Session["logined_user"] = users.UserName.ToString();
            ObjectsFields obj = new ObjectsFields();
            DataSet ds = null;
            int nPage = 1;
            obj.GetList("", "", -1, -1, out nPage, out ds, GV.cn, GV.trans);
            GroupPermission per = new GroupPermission();
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                Session[dr["code"].ToString()] = per.GetUserGroupPermissions(userID.ToString(), dr["ID"].ToString(), GV.cn, GV.trans);
            }
            //Get List Province Where user in 
            //Session["UserLocation"] = GroupPermission.GetAllUserLocation(userID.ToString(), GV.cn, GV.trans) + "," + Session["UserProvince"].ToString();            
            Session["UserLocation"] = "";
            Session["UserLocationIDs"] = "-1";
            if (users.VungIDs.Length > 0)
            {
                Session["UserLocation"] = Tinh.GetListIDByVungIDs(users.VungIDs, GV.cn, GV.trans);
                Session["UserLocationIDs"] = users.VungIDs.ToString();
            }
            Session["UserGroup"] = GroupPermission.GetAllUserGroupCode(userID.ToString(), GV.cn, GV.trans);
            if (Request.Cookies["UserSettings"] != null && Request.Cookies["UserSettings"].Value.ToLower() == "allowlogin")
                Response.Redirect("Default.aspx");
            else
            {
                if (int.Parse(Session["SetLogin"].ToString()) > 7 || int.Parse(Session["superadmin"].ToString()) > 7)
                    Response.Redirect("Default.aspx");
                else
                    Response.Redirect("Login.aspx");

            }

        }
    }
}
